import axios from "axios";

// @ts-ignore
const submitRoughResult= async (data,id)=>{
    const url = "/api/rough-task/uploadResult?taskId="+id;
    const userId = sessionStorage.getItem("user.id");

    return new Promise((resolve, reject) => {
        axios.post(url, data).then((response)=>{
            if (response.data == true){
                axios.get("/api/rough-task/submit",{
                    params:{
                        taskId: id,
                        crowdId: userId
                    }
                }).then((response)=>{
                    if (response.data == false){
                        alert("任务已经提交")
                    }else {
                        alert("提交成功")
                        location.reload();
                    }
                })
            } else {
                alert("提交失败")
                console.log(resolve);
                console.log(reject)
            }
        }).catch((reason) => {
            resolve = reason;
            alert("提交失败")
        })
    })
}
export default submitRoughResult;